//
//  MusicCollectionViewCell.m
//  OurRelaxDemo
//
//  Created by 王雅蓉 on 15/6/23.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "MusicCollectionViewCell.h"

#import <UIImageView+WebCache.h>

@interface MusicCollectionViewCell ()

@end

@implementation MusicCollectionViewCell

-(void)dealloc
{
    [_imageV release];
    [_mainTitle release];
    [_subTitle release];
    [_newMusic release];
    
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        //self.backgroundColor = [UIColor lightGrayColor];
        
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height - 35)];
        _imageV.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_imageV];
        [_imageV release];
        
        _mainTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, _imageV.frame.size.height, frame.size.width, 20)];
        _mainTitle.font = [UIFont systemFontOfSize:14.0];
        _mainTitle.textColor = [UIColor darkGrayColor];
        //_mainTitle.text = @"哈哈";
        [self.contentView addSubview:_mainTitle];
        [_mainTitle release];
        
        _subTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, _mainTitle.frame.origin.y + _mainTitle.frame.size.height, frame.size.width, 15)];
        _subTitle.font = [UIFont systemFontOfSize:11.0];
        _subTitle.textColor = [UIColor lightGrayColor];
        //_subTitle.text = @"嘿嘿";
        [self.contentView addSubview:_subTitle];
        [_subTitle release];
    }
    
    return self;
}

-(void)setNewMusic:(MusicModel *)newMusic
{
    if (_newMusic != newMusic) {
        
        [_newMusic release];
        _newMusic = [newMusic retain];
        
    }
    
    NSString *urlStr = [newMusic.pic stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];
    [_imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"musicWebCache.jpeg"]];
    
    _mainTitle.text = newMusic.title;
    _subTitle.text = newMusic.desc;
}

@end
